// pages/zlk/zlk.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [{
        title: '2023国考情报站',
        fm: 'https://sd.offcn.com/zg/wximg/2022/gk/zllq/f1.png',
         lists: [
           {
            name: '2023国考情报站',
            sid: 1
          }
        ]
      },
      {
        title: '2023国考常识积累手册',
        fm: 'https://sd.offcn.com/zg/wximg/2022/gk/zllq/f2.png',
        lists: [
          {
            name: '2023国考常识积累手册',
            sid: 2
          }
        ]
      },
    
     
    ],
    activity_id: 25
  },
  topdf(e) {
    var _ = this;
    var phone = wx.getStorageSync('zllqphone')
    if (phone) {
      console.log(e.currentTarget.dataset.sid)
      var sid = e.currentTarget.dataset.sid;
      wx.navigateTo({
        url: '../pdf/pdf?sid=' + sid,
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      });
      _.setData({
        login: 1
      })
    }
  },
  zixun(e) {
    var _ = this;
    wx.navigateTo({
      url: '../zixun/zixun',
    })
  },
  close(e) {
    var _ = this;
    _.setData({
      login:!1
    })
  },
  getPhoneNumber(e) {
    var _ = this;
    var flag = _.data.flag;
    if (flag) {
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      _.setData({
        mobile: res.result,
      })
      console.log(res.result)
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 36,
          mobile: res.result,
          areaCode: _.data.area,
          agent: _.data.geneal,
          pageId: _.data.page
        },
        success: res => {
          console.log(res);
        }
      })

      wx.setStorageSync('zllqphone', _.data.mobile)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/biaodan/register?actid=46828&callback=?', //接收url
        data: {
          phone: _.data.mobile,
          fenxiao: _.data.area,
          geneal: _.data.geneal,
          isagree:true
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          _.setData({
            login: 0
          })
        }
      });



    })
  } else {
    wx.showToast({
      title: '请先勾选隐私协议！',
      icon: 'none'
    })
  }
  },
  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../../agreement/agreement',
    })
  },
  //选择条目
  tabSelect(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      list: e.currentTarget.dataset.id,
      tabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 2) * 200
    })
  },
  tohb() {
    wx.navigateTo({
      url: '../tuiwen/tuiwen',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _ = this;
    console.log(options);
    _.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      _.setData({
        page: options.page
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})